import os
import sys
localDir = os.path.dirname(__file__)
curpath = os.path.normpath(os.path.join(os.getcwd(), localDir))
grandparent = os.path.normpath(os.path.join(curpath, '../'))
sys.path.insert(0, grandparent)

import unittest

from lib.drop_table import DropTable

from databases.alchemy import Alchemy

config = {"development" : {"db" : "sqlite:///:memory:"}}

class TestDropTable(unittest.TestCase):

    def testTruth(self):
        self.assertTrue(True)

    def testInitialiaze(self):
        alc = Alchemy(config['development']['db'])
        alc._create_schema()

        result = alc.execute_raw_query("SELECT * FROM schema_info").fetchone()
        self.assertEquals('000', result[0])
        query = "schema_info"
        sql = DropTable(alc, query)

        self.assertEqual("schema_info", sql.table)

    def testExecute(self):
        alc = Alchemy(config['development']['db'])
        alc._create_schema()
        result = alc.execute_raw_query("SELECT * FROM schema_info").fetchone()
        self.assertEquals('000', result[0])
        
        query = "schema_info"
        sql = DropTable(alc, query)

        self.assertTrue(sql.execute())

        try:
            alc.execute_raw_query("SELECT * FROM schema_info").fetchone()
        except:
            pass

if __name__ == "__main__":
    unittest.main()
